<template>
  <div class="about">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">
            <div class="layui-card-header">修改密码</div>
            <div class="layui-card-body" pad15="">
              <div class="layui-form" lay-filter="">
                <div class="layui-form-item">
                  <label class="layui-form-label">当前密码</label>
                  <div class="layui-input-inline">
                    <input type="password" name="oldPassword" v-model="oldPassword" lay-verify="required" lay-vertype="tips" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">新密码</label>
                  <div class="layui-input-inline">
                    <input type="password" name="password" minlength="6" maxlength="12"  v-model="password" lay-verify="pass" lay-vertype="tips" autocomplete="off" id="LAY_password" class="layui-input">
                  </div>
                  <div class="layui-form-mid layui-word-aux">6到12个字符</div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">确认新密码</label>
                  <div class="layui-input-inline">
                    <input type="password" name="repassword" minlength="6" maxlength="12" v-model="repassword" lay-verify="repass" lay-vertype="tips" autocomplete="off" class="layui-input">
                  </div>
                </div>
                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="setmypass" @click="submitDate">确认修改</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import md5 from 'js-md5';
export default {
  components: {},
  data() {
    return {
      oldPassword: "",
      password: "",
      repassword: "",
    };
  },
  methods: {
    submitDate: function () {
      var T = this;
      if(T.password!==T.repassword ){
        T.$XModal.message('新密码前后填写不一致',{status:'error'});
        return;
      }
      var str=T.repassword;
      if(str.length <6){
        T.$XModal.message('请控制密码长度在6-12个字符之间',{status:'error'});
        return;
      }
      var params={
        oldPassword:md5(T.oldPassword)||"",
        newPassowrd:md5(T.repassword)||""
      }

      this.$请求('/up/password',params,function(result){
         if(result.data.code!==1){
           T.$XModal.message(result.data.message,{status:'error'});
           return;
         }else{
           T.$XModal.message('修改密码成功,请重新登录',{status:'success'});
           T.$router.push('/login');
           return;
         }
      })
    },
  },
};
</script>
